package utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import Entity.AutocarEntity;
import Entity.BuilderEntity;
import Entity.ManufacturyEntity;
import Entity.OfficeEntity;
import Entity.SupEntity;
import Entity.ToolEntity;
import android.util.Xml;


public class XmlTemplateParser {
	 private static final String ns = null;
	 public SupEntity parse(InputStream in) throws XmlPullParserException, IOException {   
		 try {
         XmlPullParser parser = Xml.newPullParser();
         parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);       
         parser.setInput(in , null);
         parser.nextTag();       
         return readTemplateXml(parser); 
	 } finally {
         in.close();
     }
 }
	 
	 private SupEntity readTemplateXml(XmlPullParser parser) throws XmlPullParserException, IOException {
		 parser.require(XmlPullParser.START_TAG, ns, "data");
		 SupEntity sEntity = new SupEntity();
		  while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("supname")) {
	            	sEntity.setSupname(readSupname(parser));
	            } else if (name.equals("supcodep")) {
	            	sEntity.setSupcodep(readSupcodep(parser));
	            }
	            else if (name.equals("supcodef")) {
	            	sEntity.setSupcodef(readSupcodef(parser));
	            }else if (name.equals("car")) {
	            	sEntity.setCar(readCar(parser));
	            }else if (name.equals("carcodeoil")) {
	            	sEntity.setCarcodeoil(readCarcodeoil(parser));
	            
	        	}else if (name.equals("carcodezp")) {
	        		sEntity.setCarcodezp(readCarcodezp(parser));
	        	
	    		}
		  		else if (name.equals("statusov")) {
		  			sEntity.setStatusov(readStatusov(parser));
      	
		  		}
		  		else if (name.equals("v")) {
		  			sEntity.setV(readV(parser));
      	
		  		}
		  		else if (name.equals("r")) {
		  			sEntity.setR(readR(parser));
      	
		  		}
		  		else if (name.equals("o")) {
		  			sEntity.setO(readO(parser));
      	
		  		}
		  		else if (name.equals("ostatok")) {
		  			sEntity.setOstatok(readOstatok(parser));
      	
		  		}
		  		else if (name.equals("kassa")) {
		  			sEntity.setKassa(readKassa(parser));
      	
		  		}
		  		else if (name.equals("postavkavalue")) {
		  			sEntity.setPostavkavalue(readPostavkavalue(parser));
      	
		  		}
		  		else if (name.equals("agentvalue")) {
		  			sEntity.setAgentvalue(readAgentvalue(parser));
      	
		  		}
		  		else if (name.equals("zakupkavalue")) {
		  			sEntity.setZakupkavalue(readZakupkavalue(parser));
      	
		  		}
		  		else if (name.equals("gsmvalue")) {
		  			sEntity.setGsmvalue(readGsmvalue(parser));
      	
		  		}
		  		else if (name.equals("oworkervalue")) {
		  			sEntity.setOworkervalue(readOworkervalue(parser));
      	
		  		}
		  		else if (name.equals("prazvalue")) {
		  			sEntity.setPrazvalue(readPrazvalue(parser));
      	
		  		}
		  		else if (name.equals("payvalue")) {
		  			sEntity.setPayvalue(readPayvalue(parser));
      	
		  		}
		  		else if (name.equals("bdohodvalue")) {
		  			sEntity.setBdohodvalue(readBdohodvalue(parser));
      	
		  		}
		  		else if (name.equals("adohodvalue")) {
		  			sEntity.setAdohodvalue(readAdohodvalue(parser));
      	
		  		}
		  		else if (name.equals("zdohodvalue")) {
		  			sEntity.setZdohodvalue(readZdohodvalue(parser));
      	
		  		}
		  		else if (name.equals("proizvodstvovalue")) {
		  			sEntity.setProizvodstvovalue(readProizvodstvovalue(parser));
      	
		  		}
		  		else if (name.equals("stroikavalue")) {
		  			sEntity.setStroikavalue(readStroikavalue(parser));
      	
		  		}
		  		else if (name.equals("officevalue")) {
		  			sEntity.setOfficevalue(readOfficevalue(parser));
      	
		  		}
		  		else if (name.equals("autovalue")) {
		  			sEntity.setAutovalue(readAutovalue(parser));
      	
		  		}
		  		else if (name.equals("toolsvalue")) {
		  			sEntity.setToolsvalue(readToolsvalue(parser));
      	
		  		}
		  		else if (name.equals("othervalue")) {
		  			sEntity.setOthervalue(readOthervalue(parser));
      	
		  		}
		  		else if (name.equals("distributors")) {
		  			sEntity.setDistributors(readDistributors(parser));
      	
		  		}
		  		else if (name.equals("agents")) {
		  			sEntity.setAgents(readAgents(parser));
      	
		  		}
		  		else if (name.equals("prazs")) {
		  			sEntity.setPrazs(readPrazs(parser));
      	
		  		}
		  		else if (name.equals("pays")) {
		  			sEntity.setPays(readPays(parser));
      	
		  		}
		  		else if (name.equals("bdohods")) {
		  			sEntity.setBdohods(readBdohods(parser));
      	
		  		}
		  		else if (name.equals("adohods")) {
		  			sEntity.setAdohods(readAdohods(parser));
      	
		  		}
		  		else if (name.equals("zdohods")) {
		  			sEntity.setZdohods(readZdohods(parser));
      	
		  		}
		  		else if (name.equals("oworkers")) {
		  			sEntity.setOworkers(readOworkers(parser));
      	
		  		}
		  		else if (name.equals("manufactures")) {
		  			sEntity.setManufactures(readManufactures(parser));
      	
		  		}
		  		else if (name.equals("autocars")) {
		  			sEntity.setAutocars(readAutocars(parser));
      	
		  		}
		  		else if (name.equals("builders")) {
		  			sEntity.setBuilders(readBuilders(parser));
      	
		  		}
		  		else if (name.equals("gsms")) {
		  			sEntity.setGsms(readGsms(parser));
      	
		  		}
		  		else if (name.equals("offices")) {
		  			sEntity.setOffices(readOffices(parser));
      	
		  		}
		  		else if (name.equals("tools")) {
		  			sEntity.setTools(readTools(parser));
      	
		  		}
		  		else if (name.equals("others")) {
		  			sEntity.setOthers(readOthers(parser));
      	
		  		}
	            	else {
	                skip(parser);
	            }
	        }
		 return sEntity;
	 }
	 private String readSupname(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "supname");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "supname");
	        return data;
	    }
	 private String readSupcodep(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "supcodep");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "supcodep");
	        return data;
	    }
	 private String readSupcodef(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "supcodef");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "supcodef");
	        return data;
	    }
	 private String readCar(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "car");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "car");
	        return data;
	    }
	 private String readCarcodeoil(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "carcodeoil");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "carcodeoil");
	        return data;
	    }
	 private String readCarcodezp(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "carcodezp");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "carcodezp");
	        return data;
	    }
	 private String readStatusov(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "statusov");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "statusov");
	        return data;
	    }
	 private String readV(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "v");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "v");
	        return data;
	    }
	 private String readR(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "r");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "r");
	        return data;
	    }
	 private String readO(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "o");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "o");
	        return data;
	    }
	 private String readOstatok(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "ostatok");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "ostatok");
	        return data;
	    }
	 private String readKassa(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "kassa");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "kassa");
	        return data;
	    }
	 private String readPostavkavalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "postavkavalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "postavkavalue");
	        return data;
	    }
	 private String readAgentvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "agentvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "agentvalue");
	        return data;
	    }
	 private String readZakupkavalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "zakupkavalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "zakupkavalue");
	        return data;
	    }
	 private String readPayvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "payvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "payvalue");
	        return data;
	    }
	 private String readBdohodvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "bdohodvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "bdohodvalue");
	        return data;
	    }
	 private String readAdohodvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "adohodvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "adohodvalue");
	        return data;
	    }
	 private String readZdohodvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "zdohodvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "zdohodvalue");
	        return data;
	    }
	 private String readGsmvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "gsmvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "gsmvalue");
	        return data;
	    }
	 private String readOworkervalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "oworkervalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "oworkervalue");
	        return data;
	    }
	 private String readPrazvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "prazvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "prazvalue");
	        return data;
	    }
	 private String readProizvodstvovalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "proizvodstvovalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "proizvodstvovalue");
	        return data;
	    }
	 private String readStroikavalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "stroikavalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "stroikavalue");
	        return data;
	    }
	 private String readOfficevalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "officevalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "officevalue");
	        return data;
	    }
	 private String readAutovalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "autovalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "autovalue");
	        return data;
	    }
	 private String readToolsvalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "toolsvalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "toolsvalue");
	        return data;
	    }
	 private String readOthervalue(XmlPullParser parser) throws IOException, XmlPullParserException {
	        parser.require(XmlPullParser.START_TAG, ns, "othervalue");
	        String data = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "othervalue");
	        return data;
	    }
	 
	 
	 private ArrayList<MyTreeSet> readDistributors(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyTreeSet> list= new ArrayList<MyTreeSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "distributors");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("distributor")) {
	            	 list.add(readDistributor(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedTreeSet<String, String, String> readDistributor (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "postname");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "postname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "postcode");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "postcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "postsumm");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "postsumm");
	        parser.next();
	        parser.next();
	        OrderedTreeSet <String, String, String> distributor = new  OrderedTreeSet<String, String, String>(key,value1,value2);
		 return  distributor;
	 }
	 private ArrayList<MyTreeSet> readAgents(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyTreeSet> list= new ArrayList<MyTreeSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "agents");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("agent")) {
	            	 list.add(readAgent(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedTreeSet<String, String, String> readAgent (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "agname");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "agname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "agcode");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "agcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "agsumm");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "agsumm");
	        parser.next();
	        parser.next();
	        OrderedTreeSet <String, String, String> agent = new  OrderedTreeSet<String, String, String>(key,value1,value2);
		 return  agent;
	 }
	 private ArrayList<Pair> readPrazs(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<Pair> list= new ArrayList<Pair>();
	        parser.require(XmlPullParser.START_TAG, ns, "prazs");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("praz")) {
	            	 list.add(readPraz(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedPair<String, String> readPraz (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "prazname");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "prazname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "prazsumm");     
	        value = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "prazsumm");
	        parser.next();
	        parser.next();
	        OrderedPair <String, String> agent = new  OrderedPair<String, String>(key,value);
		 return  agent;
	 }
	 private ArrayList<MyTreeSet> readPays(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyTreeSet> list= new ArrayList<MyTreeSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "pays");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("pay")) {
	            	 list.add(readPay(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedTreeSet<String, String, String> readPay (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "payname");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "payname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "paycode");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "paycode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "paysumm");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "paysumm");
	        parser.next();
	        parser.next();
	        OrderedTreeSet <String, String, String> pay = new  OrderedTreeSet<String, String, String>(key,value1,value2);
		 return  pay;
	 }
	 private ArrayList<MyTreeSet> readBdohods(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyTreeSet> list= new ArrayList<MyTreeSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "bdohods");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("bdohod")) {
	            	 list.add(readBdohod(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedTreeSet<String, String, String> readBdohod (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "bdohodname");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "bdohodname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "bdohoddate");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "bdohoddate");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "bdohodsumm");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "bdohodsumm");
	        parser.next();
	        parser.next();
	        OrderedTreeSet <String, String, String> bdohod = new  OrderedTreeSet<String, String, String>(key,value1,value2);
		 return  bdohod;
	 }
	 private ArrayList<MyFourSet> readAdohods(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyFourSet> list= new ArrayList<MyFourSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "adohods");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("adohod")) {
	            	 list.add(readAdohod(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedFourSet<String, String, String, String> readAdohod (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 String value3 = null ;
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "adohodname");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "adohodname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "adohodcode");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "adohodcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "adohodsumm");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "adohodsumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "adohoddate");     
	        value3 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "adohoddate");
	        parser.next();
	        parser.next();
	        OrderedFourSet <String, String, String , String> adohod = new  OrderedFourSet<String, String, String, String>(key,value1,value2,value3);
		 return  adohod;
	 }
	 private ArrayList<MyTreeSet> readZdohods(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyTreeSet> list= new ArrayList<MyTreeSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "zdohods");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("zdohod")) {
	            	 list.add(readZdohod(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedTreeSet<String, String, String> readZdohod (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "zdohodnumber");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "zdohodnumber");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "zdohodsumm");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "zdohodsumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "zdohoddate");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "zdohoddate");
	        parser.next();
	        parser.next();
	        OrderedTreeSet <String, String, String> zdohod = new  OrderedTreeSet<String, String, String>(key,value1,value2);
		 return  zdohod;
	 }
	 private ArrayList<MyTreeSet> readOworkers(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyTreeSet> list= new ArrayList<MyTreeSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "oworkers");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("oworker")) {
	            	 list.add(readOworker(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedTreeSet<String, String, String> readOworker (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "oworkername");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "oworkername");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "oworkerdate");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "oworkerdate");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "oworkersumm");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "oworkersumm");
	        parser.next();
	        parser.next();
	        OrderedTreeSet <String, String, String> oworker = new  OrderedTreeSet<String, String, String>(key,value1,value2);
		 return  oworker;
	 }
	 private ArrayList<ManufacturyEntity> readManufactures(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<ManufacturyEntity> list= new ArrayList<ManufacturyEntity>();
	        parser.require(XmlPullParser.START_TAG, ns, "manufactures");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("manufacture")) {
	            	 list.add(readManufacture(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private ManufacturyEntity readManufacture (XmlPullParser parser)throws IOException, XmlPullParserException {
		 ManufacturyEntity mEntity = new ManufacturyEntity();
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "manuname");
		 mEntity.setManuname(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manuname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manucode");     
	        mEntity.setManucode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manucode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manuunit");     
	        mEntity.setManuunit(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manuunit");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manuunitcode");     
	        mEntity.setManuunitcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manuunitcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manuamount");     
	        mEntity.setManuamount(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manuamount");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manuprice");     
	        mEntity.setManuprice(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manuprice");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manusumm");     
	        mEntity.setManusumm(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manusumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "manusummdrob");     
	        mEntity.setManusummdrob(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "manusummdrob");
	        parser.next();
	        parser.next();
		 return  mEntity;
	 }
	 private ArrayList<AutocarEntity> readAutocars(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<AutocarEntity> list= new ArrayList<AutocarEntity>();
	        parser.require(XmlPullParser.START_TAG, ns, "autocars");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("autocar")) {
	            	 list.add(readAutocar(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private AutocarEntity readAutocar (XmlPullParser parser)throws IOException, XmlPullParserException {
		 AutocarEntity mEntity = new AutocarEntity();
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "agroupcode");
		 mEntity.setAgroupcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "agroupcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autoname");     
	        mEntity.setAutoname(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autoname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autocode");     
	        mEntity.setAutocode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autocode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autounit");     
	        mEntity.setAutounit(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autounit");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autounitcode");     
	        mEntity.setAutounitcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autounitcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autoamount");     
	        mEntity.setAutoamount(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autoamount");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autoprice");     
	        mEntity.setAutoprice(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autoprice");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autosumm");     
	        mEntity.setAutosumm(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autosumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "autosummdrob");     
	        mEntity.setAutosummdrob(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "autosummdrob");
	        parser.next();
	        parser.next();
		 return  mEntity;
	 }
	 private ArrayList<BuilderEntity> readBuilders(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<BuilderEntity> list= new ArrayList<BuilderEntity>();
	        parser.require(XmlPullParser.START_TAG, ns, "builders");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("builder")) {
	            	 list.add(readBuilder(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private BuilderEntity readBuilder (XmlPullParser parser)throws IOException, XmlPullParserException {
		 BuilderEntity mEntity = new BuilderEntity();
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "bgroupcode");
		 mEntity.setBgroupcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "bgroupcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builname");     
	        mEntity.setBuilname(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builcode");     
	        mEntity.setBuilcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builunit");     
	        mEntity.setBuilunit(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builunit");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builunitcode");     
	        mEntity.setBuilunitcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builunitcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builamount");     
	        mEntity.setBuilamount(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builamount");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builprice");     
	        mEntity.setBuilprice(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builprice");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builsumm");     
	        mEntity.setBuilsumm(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builsumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "builsummdrob");     
	        mEntity.setBuilsummdrob(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "builsummdrob");
	        parser.next();
	        parser.next();
		 return  mEntity;
	 }
	 private ArrayList<Pair> readGsms(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<Pair> list= new ArrayList<Pair>();
	        parser.require(XmlPullParser.START_TAG, ns, "gsms");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("gsm")) {
	            	 list.add(readGsm(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedPair<String, String> readGsm (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value = null ; 
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "gsmdate");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "gsmdate");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "gsmsumm");     
	        value = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "gsmsumm");
	        parser.next();
	        parser.next();
	        OrderedPair <String, String> gsm = new  OrderedPair<String, String>(key,value);
		 return  gsm;
	 }
	 

	 private ArrayList<OfficeEntity> readOffices(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<OfficeEntity> list= new ArrayList<OfficeEntity>();
	        parser.require(XmlPullParser.START_TAG, ns, "offices");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("office")) {
	            	 list.add(readOffice(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OfficeEntity readOffice (XmlPullParser parser)throws IOException, XmlPullParserException {
		 OfficeEntity mEntity = new OfficeEntity();
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "officegroupcode");
		 mEntity.setOfficegroupcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officegroupcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officename");     
	        mEntity.setOfficename(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officename");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officecode");     
	        mEntity.setOfficecode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officecode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officeunit");     
	        mEntity.setOfficeunit(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officeunit");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officeunitcode");     
	        mEntity.setOfficeunitcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officeunitcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officeamount");     
	        mEntity.setOfficeamount(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officeamount");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officeprice");     
	        mEntity.setOfficeprice(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officeprice");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officesumm");     
	        mEntity.setOfficesumm(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officesumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "officesummdrob");     
	        mEntity.setOfficesummdrob(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "officesummdrob");
	        parser.next();
	        parser.next();
		 return  mEntity;
	 }

	 private ArrayList<ToolEntity> readTools(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<ToolEntity> list= new ArrayList<ToolEntity>();
	        parser.require(XmlPullParser.START_TAG, ns, "tools");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("tool")) {
	            	 list.add(readTool(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private ToolEntity readTool (XmlPullParser parser)throws IOException, XmlPullParserException {
		 ToolEntity mEntity = new ToolEntity();
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "toolgroupcode");
		 mEntity.setToolgroupcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolgroupcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolname");     
	        mEntity.setToolname(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolname");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolcode");     
	        mEntity.setToolcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolunit");     
	        mEntity.setToolunit(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolunit");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolunitcode");     
	        mEntity.setToolunitcode(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolunitcode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolamount");     
	        mEntity.setToolamount(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolamount");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolprice");     
	        mEntity.setToolprice(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolprice");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolsumm");     
	        mEntity.setToolsumm(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolsumm");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "toolsummdrob");     
	        mEntity.setToolsummdrob(readText(parser));
	        parser.require(XmlPullParser.END_TAG, ns, "toolsummdrob");
	        parser.next();
	        parser.next();
		 return  mEntity;
	 }
	 
	 private ArrayList<MyFourSet> readOthers(XmlPullParser parser) throws IOException, XmlPullParserException {
	    	ArrayList<MyFourSet> list= new ArrayList<MyFourSet>();
	        parser.require(XmlPullParser.START_TAG, ns, "others");
	        while (parser.next() != XmlPullParser.END_TAG) {
	            if (parser.getEventType() != XmlPullParser.START_TAG) {
	                continue;
	            }
	            String name = parser.getName();
	            if (name.equals("other")) {
	            	 list.add(readOther(parser)) ;}
	            
	        	 else {
	                skip(parser);
	            }
	        }

	        return list;
	    }
	 
	 private OrderedFourSet<String, String, String, String> readOther (XmlPullParser parser)throws IOException, XmlPullParserException {
		 String key = null ; 
		 String value1 = null ; 
		 String value2 = null ; 
		 String value3 = null ;
		 parser.next();
	     parser.next();
		 parser.require(XmlPullParser.START_TAG, ns, "othercode");
	      key= readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "othercode");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "othername");     
	        value1 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "othername");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "otherdesc");     
	        value2 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "otherdesc");
	        parser.next();
	        parser.next();
	        parser.require(XmlPullParser.START_TAG, ns, "othersumm");     
	        value3 = readText(parser);
	        parser.require(XmlPullParser.END_TAG, ns, "othersumm");
	        parser.next();
	        parser.next();
	        OrderedFourSet <String, String, String , String> other = new  OrderedFourSet<String, String, String, String>(key,value1,value2,value3);
		 return  other;
	 }
	 
	  public static String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
	        String result = null;
	        if (parser.next() == XmlPullParser.TEXT) {
	            result = parser.getText();
	            if(result.equals(" ") ||result.equals("")){
	            	result = "0";
	            }
	            parser.nextTag();
	        }
	        return result;
	    }
	  

	
	  public static void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
	        if (parser.getEventType() != XmlPullParser.START_TAG) {
	            throw new IllegalStateException();
	        }
	        int depth = 1;
	        while (depth != 0) {
	            switch (parser.next()) {
	            case XmlPullParser.END_TAG:
	                    depth--;
	                    break;
	            case XmlPullParser.START_TAG:
	                    depth++;
	                    break;
	            }
	        }
	    }   
}
